﻿using Api.Common;
using Api.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Api.DAL
{
    /// <summary>
	/// 数据访问类:eazy_wf_instance
	/// </summary>
	public partial class wf_instance
    {
        public wf_instance()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from eazy_wf_instance");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists_C(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from eazy_wf_instance");
            strSql.Append(" where case_id=@case_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@case_id", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Models.wf_instance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into eazy_wf_instance(");
            strSql.Append("WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,report_id,case_id,resolved_id,final_report_id,add_time,group_time )");
            strSql.Append(" values (");
            strSql.Append("@WF_TempID,@InstName,@WFApplicationId,@SubBy,@SubTime,@EndTime,@Status,@DelFlag,@Remark,@InstanceForm,@report_id,@case_id,@resolved_id,@final_report_id,@add_time,@group_time )");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@WF_TempID", SqlDbType.Int,4),
                    new SqlParameter("@InstName", SqlDbType.NVarChar,150),
                    new SqlParameter("@WFApplicationId", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@SubBy", SqlDbType.Int,4),
                    new SqlParameter("@SubTime", SqlDbType.DateTime),
                    new SqlParameter("@EndTime", SqlDbType.DateTime),
                    new SqlParameter("@Status", SqlDbType.Int,4),
                    new SqlParameter("@DelFlag", SqlDbType.Int,4),
                    new SqlParameter("@Remark", SqlDbType.NVarChar,250),
                    new SqlParameter("@InstanceForm", SqlDbType.NVarChar,550),
                    new SqlParameter("@report_id", SqlDbType.Int,4),
                    new SqlParameter("@case_id", SqlDbType.Int,4),
                    new SqlParameter("@resolved_id", SqlDbType.Int,4),
                    new SqlParameter("@final_report_id", SqlDbType.Int,4),
                    new SqlParameter("@add_time", SqlDbType.DateTime),
                    new SqlParameter("@group_time", SqlDbType.NVarChar,20),};
            parameters[0].Value = model.WF_TempID;
            parameters[1].Value = model.InstName;
            parameters[2].Value = model.WFApplicationId;
            parameters[3].Value = model.SubBy;
            parameters[4].Value = model.SubTime;
            parameters[5].Value = model.EndTime;
            parameters[6].Value = model.Status;
            parameters[7].Value = model.DelFlag;
            parameters[8].Value = model.Remark;
            parameters[9].Value = model.InstanceForm;
            parameters[10].Value = model.report_id;
            parameters[11].Value = model.case_id;
            parameters[12].Value = model.resolved_id;
            parameters[13].Value = model.Final_report_id;
            parameters[14].Value = model.add_time;
            parameters[15].Value = model.group_time;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Models.wf_instance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update eazy_wf_instance set ");
            strSql.Append("WF_TempID=@WF_TempID,");
            strSql.Append("InstName=@InstName,");
            strSql.Append("WFApplicationId=@WFApplicationId,");
            strSql.Append("SubBy=@SubBy,");
            strSql.Append("SubTime=@SubTime,");
            strSql.Append("EndTime=@EndTime,");
            strSql.Append("Status=@Status,");
            strSql.Append("DelFlag=@DelFlag,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("InstanceForm=@InstanceForm,");
            strSql.Append("operator=@operator,");
            strSql.Append("case_id=@case_id,");
            strSql.Append("resolved_id=@resolved_id,");
            strSql.Append("final_report_id=@final_report_id");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@WF_TempID", SqlDbType.Int,4),
                    new SqlParameter("@InstName", SqlDbType.NVarChar,150),
                    new SqlParameter("@WFApplicationId", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@SubBy", SqlDbType.Int,4),
                    new SqlParameter("@SubTime", SqlDbType.DateTime),
                    new SqlParameter("@EndTime", SqlDbType.DateTime),
                    new SqlParameter("@Status", SqlDbType.Int,4),
                    new SqlParameter("@DelFlag", SqlDbType.Int,4),
                    new SqlParameter("@Remark", SqlDbType.NVarChar,250),
                    new SqlParameter("@InstanceForm", SqlDbType.NVarChar,550),
                    new SqlParameter("@operator", SqlDbType.Int,4),
                    new SqlParameter("@case_id", SqlDbType.Int,4),
                    new SqlParameter("@resolved_id", SqlDbType.Int,4),
                    new SqlParameter("@final_report_id", SqlDbType.Int,4),
                    new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = model.WF_TempID;
            parameters[1].Value = model.InstName;
            parameters[2].Value = model.WFApplicationId;
            parameters[3].Value = model.SubBy;
            parameters[4].Value = model.SubTime;
            parameters[5].Value = model.EndTime;
            parameters[6].Value = model.Status;
            parameters[7].Value = model.DelFlag;
            parameters[8].Value = model.Remark;
            parameters[9].Value = model.InstanceForm;
            parameters[10].Value = model.Operator;
            parameters[11].Value = model.case_id;
            parameters[12].Value = model.resolved_id;
            parameters[13].Value = model.Final_report_id;
            parameters[14].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from eazy_wf_instance ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteAll_P(Models.wf_instance model)
        {
            #region
            ////取得立案审批附件表MODEL
            //List<Model.case_attach> case_attach = new DAL.case_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得案件移送附件表MODEL
            //List<Model.case_remove_attach> case_remove_attach = new DAL.case_remove_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得销案审批附件表MODEL
            //List<Model.case_revoke_attach> case_revoke_attach = new DAL.case_revoke_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得现场检查笔录附件表MODEL
            //List<Model.checked_attach> checked_attach = new DAL.checked_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得结案报告附件表MODEL
            //List<Model.end_report_attach> end_report_attach = new DAL.end_report_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得先行登记保存证据处理决定书附件表MODEL
            //List<Model.evidence_resolved_attach> evidence_resolved_attach = new DAL.evidence_resolved_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得案件调查终结报告附件表MODEL
            //List<Model.report_attach> report_attach = new DAL.report_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得案件处理审批表附件表MODEL
            //List<Model.subject_attach> subject_attach = new DAL.subject_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得案件听证笔录附件表MODEL
            //List<Model.tz_record_attach> tz_record_attach = new DAL.tz_record_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得行政处罚告知书附件MODEL
            //List<Model.xzcf_notify_attach> xzcf_notify_attach = new DAL.xzcf_notify_attach("eazy_").GetList_I(model.ID.ToString());
            ////取得行政处罚决定书附件MODEL
            //List<Model.xzcf_resolved_attach> xzcf_resolved_attach = new DAL.xzcf_resolved_attach("eazy_").GetList_I(model.ID.ToString());

            //#region 主要SQL ===========================
            ////删除实例主表
            //StringBuilder strSql1 = new StringBuilder();
            //strSql1.Append("delete from eazy_wf_instance ");
            //strSql1.Append(" where ID=@ID ");
            //SqlParameter[] parameters1 = {
            //        new SqlParameter("@ID", SqlDbType.Int,4)};
            //parameters1[0].Value = model.ID;
            //List<CommandInfo> sqllist = new List<CommandInfo>();
            //CommandInfo cmd = new CommandInfo(strSql1.ToString(), parameters1);
            //sqllist.Add(cmd);

            ////删除实例步骤主表
            //StringBuilder strSql2 = new StringBuilder();
            //strSql2.Append("delete from eazy_wf_step ");
            //strSql2.Append(" where Instance_id=@Instance_id ");
            //SqlParameter[] parameters2 = {
            //        new SqlParameter("@Instance_id", SqlDbType.Int,4)};
            //parameters2[0].Value = model.ID;
            //cmd = new CommandInfo(strSql2.ToString(), parameters2);
            //sqllist.Add(cmd);

            ////删除实例步骤副表
            //StringBuilder strSql3 = new StringBuilder();
            //strSql3.Append("delete from eazy_wf_step_info ");
            //strSql3.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters3 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters3[0].Value = model.ID;
            //cmd = new CommandInfo(strSql3.ToString(), parameters3);
            //sqllist.Add(cmd);

            ////删除案件主表
            //StringBuilder strSql4 = new StringBuilder();
            //strSql4.Append("delete from eazy_case_detail ");
            //strSql4.Append(" where id=@id ");
            //SqlParameter[] parameters4 = {
            //        new SqlParameter("@id", SqlDbType.Int,4)};
            //parameters4[0].Value = model.case_id;
            //cmd = new CommandInfo(strSql4.ToString(), parameters4);
            //sqllist.Add(cmd);

            ////删除案件附件表
            //StringBuilder strSql5 = new StringBuilder();
            //strSql5.Append("delete from eazy_case_attach ");
            //strSql5.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters5 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters5[0].Value = model.ID;
            //cmd = new CommandInfo(strSql5.ToString(), parameters5);
            //sqllist.Add(cmd);

            ////删除立案通知书
            //StringBuilder strSql7 = new StringBuilder();
            //strSql7.Append("delete from eazy_case_info_notice ");
            //strSql7.Append(" where case_id=@case_id ");
            //SqlParameter[] parameters7 = {
            //        new SqlParameter("@case_id", SqlDbType.Int,4)};
            //parameters7[0].Value = model.case_id;
            //cmd = new CommandInfo(strSql7.ToString(), parameters7);
            //sqllist.Add(cmd);

            ////删除案件调查终结报告表
            //StringBuilder strSql8 = new StringBuilder();
            //strSql8.Append("delete from eazy_report ");
            //strSql8.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters8 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters8[0].Value = model.ID;
            //cmd = new CommandInfo(strSql8.ToString(), parameters8);
            //sqllist.Add(cmd);

            ////删除询问笔录
            //StringBuilder strSql9 = new StringBuilder();
            //strSql9.Append("delete from eazy_interview ");
            //strSql9.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters9 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters9[0].Value = model.ID;
            //cmd = new CommandInfo(strSql9.ToString(), parameters9);
            //sqllist.Add(cmd);

            ////删除现场检查笔录
            //StringBuilder strSql10 = new StringBuilder();
            //strSql10.Append("delete from eazy_checked ");
            //strSql10.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters10 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters10[0].Value = model.ID;
            //cmd = new CommandInfo(strSql10.ToString(), parameters10);
            //sqllist.Add(cmd);

            ////删除案件调查终结报告附件
            //StringBuilder strSql11 = new StringBuilder();
            //strSql11.Append("delete from eazy_report_attach ");
            //strSql11.Append(" where report_id=@report_id ");
            //SqlParameter[] parameters11 = {
            //        new SqlParameter("@report_id", SqlDbType.Int,4)};
            //parameters11[0].Value = model.Final_report_id;
            //cmd = new CommandInfo(strSql11.ToString(), parameters11);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql12 = new StringBuilder();
            //strSql12.Append("delete from eazy_xzcf_notify ");
            //strSql12.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters12 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters12[0].Value = model.ID;
            //cmd = new CommandInfo(strSql12.ToString(), parameters12);
            //sqllist.Add(cmd);

            ////删除当事人陈述和申辩
            //StringBuilder strSql13 = new StringBuilder();
            //strSql13.Append("delete from eazy_averment ");
            //strSql13.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters13 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters13[0].Value = model.ID;
            //cmd = new CommandInfo(strSql13.ToString(), parameters13);
            //sqllist.Add(cmd);

            ////删除案件处理审批表
            //StringBuilder strSql14 = new StringBuilder();
            //strSql14.Append("delete from eazy_subject ");
            //strSql14.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters14 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters14[0].Value = model.ID;
            //cmd = new CommandInfo(strSql14.ToString(), parameters14);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql15 = new StringBuilder();
            //strSql15.Append("delete from eazy_xzcf_resolved ");
            //strSql15.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters15 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters15[0].Value = model.ID;
            //cmd = new CommandInfo(strSql15.ToString(), parameters15);
            //sqllist.Add(cmd);

            ////删除案件处理审批表
            //StringBuilder strSql16 = new StringBuilder();
            //strSql16.Append("delete from eazy_end_report ");
            //strSql16.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters16 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters16[0].Value = model.ID;
            //cmd = new CommandInfo(strSql16.ToString(), parameters16);
            //sqllist.Add(cmd);

            ////删除案件移动书
            //StringBuilder strSql17 = new StringBuilder();
            //strSql17.Append("delete from eazy_case_remove ");
            //strSql17.Append(" where Instance_id=@Instance_id ");
            //SqlParameter[] parameters17 = {
            //        new SqlParameter("@Instance_id", SqlDbType.Int,4)};
            //parameters17[0].Value = model.ID;
            //cmd = new CommandInfo(strSql17.ToString(), parameters17);
            //sqllist.Add(cmd);

            ////删除销案审批表
            //StringBuilder strSql18 = new StringBuilder();
            //strSql18.Append("delete from eazy_case_revoke ");
            //strSql18.Append(" where Instance_id=@Instance_id ");
            //SqlParameter[] parameters18 = {
            //        new SqlParameter("@Instance_id", SqlDbType.Int,4)};
            //parameters18[0].Value = model.ID;
            //cmd = new CommandInfo(strSql18.ToString(), parameters18);
            //sqllist.Add(cmd);

            ////删除送达回证
            //StringBuilder strSql19 = new StringBuilder();
            //strSql19.Append("delete from eazy_sendbook ");
            //strSql19.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters19 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters19[0].Value = model.ID;
            //cmd = new CommandInfo(strSql19.ToString(), parameters19);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql20 = new StringBuilder();
            //strSql20.Append("delete from eazy_xzcf_notify_attach ");
            //strSql20.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters20 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters20[0].Value = model.ID;
            //cmd = new CommandInfo(strSql20.ToString(), parameters20);
            //sqllist.Add(cmd);

            ////删除案审会记录表
            //StringBuilder strSql21 = new StringBuilder();
            //strSql21.Append("delete from eazy_anshenhui ");
            //strSql21.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters21 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters21[0].Value = model.ID;
            //cmd = new CommandInfo(strSql21.ToString(), parameters21);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql22 = new StringBuilder();
            //strSql22.Append("delete from eazy_case_remove_attach ");
            //strSql22.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters22 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters22[0].Value = model.ID;
            //cmd = new CommandInfo(strSql22.ToString(), parameters22);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql23 = new StringBuilder();
            //strSql23.Append("delete from eazy_case_revoke_attach ");
            //strSql23.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters23 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters23[0].Value = model.ID;
            //cmd = new CommandInfo(strSql23.ToString(), parameters23);
            //sqllist.Add(cmd);

            ////删除行政告知书
            //StringBuilder strSql24 = new StringBuilder();
            //strSql24.Append("delete from eazy_xzcf_resolved_attach ");
            //strSql24.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters24 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters24[0].Value = model.ID;
            //cmd = new CommandInfo(strSql24.ToString(), parameters24);
            //sqllist.Add(cmd);

            ////删除证据先行保存通知书——主信息
            //StringBuilder strSql25 = new StringBuilder();
            //strSql25.Append("delete from eazy_evidence_notify ");
            //strSql25.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters25 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters25[0].Value = model.ID;
            //cmd = new CommandInfo(strSql25.ToString(), parameters25);
            //sqllist.Add(cmd);

            ////删除证据先行保存通知书——证据物品列表
            //StringBuilder strSql26 = new StringBuilder();
            //strSql26.Append("delete from eazy_evidence_notify_attach ");
            //strSql26.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters26 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters26[0].Value = model.ID;
            //cmd = new CommandInfo(strSql26.ToString(), parameters26);
            //sqllist.Add(cmd);

            ////删除证据先行审批表——主信息
            //StringBuilder strSql27 = new StringBuilder();
            //strSql27.Append("delete from eazy_evidence_shenpi ");
            //strSql27.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters27 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters27[0].Value = model.ID;
            //cmd = new CommandInfo(strSql27.ToString(), parameters27);
            //sqllist.Add(cmd);

            ////删除证据先行审批表——证据物品列表
            //StringBuilder strSql28 = new StringBuilder();
            //strSql28.Append("delete from eazy_evidence_shenpi_attach ");
            //strSql28.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters28 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters28[0].Value = model.ID;
            //cmd = new CommandInfo(strSql28.ToString(), parameters28);
            //sqllist.Add(cmd);

            ////现场检查笔录附件表
            //StringBuilder strSql29 = new StringBuilder();
            //strSql29.Append("delete from eazy_checked_attach ");
            //strSql29.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters29 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters29[0].Value = model.ID;
            //cmd = new CommandInfo(strSql29.ToString(), parameters29);
            //sqllist.Add(cmd);

            ////结案报告附件表
            //StringBuilder strSql30 = new StringBuilder();
            //strSql30.Append("delete from eazy_end_report_attach ");
            //strSql30.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters30 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters30[0].Value = model.ID;
            //cmd = new CommandInfo(strSql30.ToString(), parameters30);
            //sqllist.Add(cmd);

            ////先行登记保存证据处理决定书
            //StringBuilder strSql31 = new StringBuilder();
            //strSql31.Append("delete from eazy_evidence_resolved ");
            //strSql31.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters31 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters31[0].Value = model.ID;
            //cmd = new CommandInfo(strSql31.ToString(), parameters31);
            //sqllist.Add(cmd);

            ////先行登记保存证据处理决定书附件表
            //StringBuilder strSql32 = new StringBuilder();
            //strSql32.Append("delete from eazy_evidence_resolved_attach ");
            //strSql32.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters32 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters32[0].Value = model.ID;
            //cmd = new CommandInfo(strSql32.ToString(), parameters32);
            //sqllist.Add(cmd);

            ////案件处理审批表附件表
            //StringBuilder strSql33 = new StringBuilder();
            //strSql33.Append("delete from eazy_subject_attach ");
            //strSql33.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters33 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters33[0].Value = model.ID;
            //cmd = new CommandInfo(strSql33.ToString(), parameters33);
            //sqllist.Add(cmd);

            ////案件听证通知书
            //StringBuilder strSql34 = new StringBuilder();
            //strSql34.Append("delete from eazy_tz_notify ");
            //strSql34.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters34 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters34[0].Value = model.ID;
            //cmd = new CommandInfo(strSql34.ToString(), parameters34);
            //sqllist.Add(cmd);

            ////案件听证笔录
            //StringBuilder strSql35 = new StringBuilder();
            //strSql35.Append("delete from eazy_tz_record ");
            //strSql35.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters35 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters35[0].Value = model.ID;
            //cmd = new CommandInfo(strSql35.ToString(), parameters35);
            //sqllist.Add(cmd);

            ////案件听证笔录附件表
            //StringBuilder strSql36 = new StringBuilder();
            //strSql36.Append("delete from eazy_tz_record_attach ");
            //strSql36.Append(" where instance_id=@instance_id ");
            //SqlParameter[] parameters36 = {
            //        new SqlParameter("@instance_id", SqlDbType.Int,4)};
            //parameters36[0].Value = model.ID;
            //cmd = new CommandInfo(strSql36.ToString(), parameters36);
            //sqllist.Add(cmd);
            //#endregion

            //int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);
            //if (rowsAffected > 0)
            //{
            //    new DAL.case_attach("eazy_").DeleteFile(case_attach); //立案审批附件表
            //    new DAL.case_remove_attach("eazy_").DeleteFile(case_remove_attach); //案件移送附件表
            //    new DAL.case_revoke_attach("eazy_").DeleteFile(case_revoke_attach); //销案审批附件表
            //    new DAL.checked_attach("eazy_").DeleteFile(checked_attach); //现场检查笔录附件表
            //    new DAL.end_report_attach("eazy_").DeleteFile(end_report_attach); //结案报告附件表
            //    new DAL.evidence_resolved_attach("eazy_").DeleteFile(evidence_resolved_attach); //先行登记保存证据处理决定书附件表
            //    new DAL.report_attach("eazy_").DeleteFile(report_attach); //案件调查终结报告附件表
            //    new DAL.subject_attach("eazy_").DeleteFile(subject_attach); //案件处理审批表附件表
            //    new DAL.tz_record_attach("eazy_").DeleteFile(tz_record_attach); //案件听证笔录附件表
            //    new DAL.xzcf_notify_attach("eazy_").DeleteFile(xzcf_notify_attach); //行政处罚告知书附件
            //    new DAL.xzcf_resolved_attach("eazy_").DeleteFile(xzcf_resolved_attach); //行政处罚决定书附件
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
            #endregion
            return true;
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from eazy_wf_instance ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到举报投诉受理登记表的id
        /// </summary>
        public string GetModelReportId(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select report_id from eazy_wf_instance ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;


            if (DbHelperSQL.GetSingle(strSql.ToString(), parameters) != null)
            {
                return DbHelperSQL.GetSingle(strSql.ToString(), parameters).ToString();

            }
            else
            {
                return "";
            }


        }

        /// <summary>
        /// 根据sql语句更新一个实例记录
        /// </summary>
        public int updateinstance(string str)
        {
            return DbHelperSQL.ExecuteSql(str);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.wf_instance GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,operator,case_id,final_report_id,resolved_id,add_time  ");
            strSql.Append(" from eazy_wf_instance");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            Models.wf_instance model = new Models.wf_instance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.wf_instance GetModel_C(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,operator,case_id,final_report_id,resolved_id,add_time  ");
            strSql.Append(" from eazy_wf_instance");
            strSql.Append(" where final_report_id=@final_report_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@final_report_id", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public int GetModelId(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id from eazy_wf_instance");
            strSql.Append(" where report_id=" + ID);
            return Utils.StrToInt(DbHelperSQL.GetSingle(strSql.ToString()).ToString(), 0);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.wf_instance GetModel_CASE(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,operator,case_id,final_report_id,resolved_id,add_time  ");
            strSql.Append(" from eazy_wf_instance");
            strSql.Append(" where case_id=@case_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@case_id", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            Models.wf_instance model = new Models.wf_instance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 根据举报投诉ID得到一个对象实体
        /// </summary>
        public Models.wf_instance GetModelByReportId(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,operator,case_id,final_report_id,resolved_id,add_time  ");
            strSql.Append(" from eazy_wf_instance");
            strSql.Append(" where report_id=@report_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@report_id", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            Models.wf_instance model = new Models.wf_instance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
		/// 根据工作流id得到一个对象实体
		/// </summary>
		public Models.wf_instance GetModelByWfId(Guid wfID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,operator,case_id,final_report_id,resolved_id,add_time  ");
            strSql.Append(" from eazy_wf_instance");
            strSql.Append(" where WFApplicationId=@WFApplicationId");
            SqlParameter[] parameters = {
                    new SqlParameter("@WFApplicationId", SqlDbType.UniqueIdentifier)
            };
            parameters[0].Value = wfID;

            Models.wf_instance model = new Models.wf_instance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.wf_instance DataRowToModel(DataRow row)
        {
            Models.wf_instance model = new Models.wf_instance();
            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = int.Parse(row["ID"].ToString());
                }
                if (row["WF_TempID"] != null && row["WF_TempID"].ToString() != "")
                {
                    model.WF_TempID = int.Parse(row["WF_TempID"].ToString());
                }
                if (row["InstName"] != null)
                {
                    model.InstName = row["InstName"].ToString();
                }
                if (row["WFApplicationId"] != null)
                {
                    model.WFApplicationId = Guid.Parse(row["WFApplicationId"].ToString());
                }
                if (row["SubBy"] != null && row["SubBy"].ToString() != "")
                {
                    model.SubBy = int.Parse(row["SubBy"].ToString());
                }
                if (row["SubTime"] != null && row["SubTime"].ToString() != "")
                {
                    model.SubTime = DateTime.Parse(row["SubTime"].ToString());
                }
                if (row["EndTime"] != null && row["EndTime"].ToString() != "")
                {
                    model.EndTime = DateTime.Parse(row["EndTime"].ToString());
                }
                if (row["Status"] != null && row["Status"].ToString() != "")
                {
                    model.Status = int.Parse(row["Status"].ToString());
                }
                if (row["DelFlag"] != null && row["DelFlag"].ToString() != "")
                {
                    model.DelFlag = int.Parse(row["DelFlag"].ToString());
                }
                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
                if (row["InstanceForm"] != null)
                {
                    model.InstanceForm = row["InstanceForm"].ToString();
                }
                if (row["operator"] != null && row["operator"].ToString() != "")
                {
                    model.Operator = int.Parse(row["operator"].ToString());
                }
                if (row["case_id"] != null && row["case_id"].ToString() != "")
                {
                    model.case_id = int.Parse(row["case_id"].ToString());
                }
                if (row["final_report_id"] != null && row["final_report_id"].ToString() != "")
                {
                    model.Final_report_id = int.Parse(row["final_report_id"].ToString());
                }
                if (row["resolved_id"] != null && row["resolved_id"].ToString() != "")
                {
                    model.resolved_id = int.Parse(row["resolved_id"].ToString());
                }
                if (row["add_time"] != null && row["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(row["add_time"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,report_id,case_id,final_report_id,resolved_id,add_time ");
            strSql.Append(" FROM eazy_wf_instance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,WF_TempID,InstName,WFApplicationId,SubBy,SubTime,EndTime,Status,DelFlag,Remark,InstanceForm,add_time ");
            strSql.Append(" FROM eazy_wf_instance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM eazy_wf_instance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.ID desc");
            }
            strSql.Append(")AS Row, T.*  from eazy_wf_instance T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM eazy_wf_instance ");
            if (strWhere != "")
            {
                strSql.Append(" where " + strWhere);
            }
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
        }
        #endregion
    }
}
